package com.hanliy.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hanyulin
 * @apiNote
 * @date 2021/12/22 10:42
 */
@Configuration
public class WxConfig {

    @Autowired
    private WxProperties wxProperties;

    /**
     * 微信小程序的配置
     *
     * @author hanyulin
     * @date 2022/1/8 14:33
     * @return cn.binarywang.wx.miniapp.api.WxMaService
     */
    @Bean
    public WxMaService wxMaMiNiAppService() {
        WxMaService wxMaService = new WxMaServiceImpl();
        WxMaDefaultConfigImpl wxMaDefaultConfig = new WxMaDefaultConfigImpl();
        wxMaDefaultConfig.setAppid(wxProperties.getMiniApp().getAppId());
        wxMaDefaultConfig.setSecret(wxProperties.getMiniApp().getAppSecret());
        wxMaService.setWxMaConfig(wxMaDefaultConfig);
        return wxMaService;
    }

    /**
     * 微信安卓配置
     *
     * @author hanyulin
     * @date 2022/1/8 14:37
     * @return me.chanjar.weixin.mp.api.WxMpService
     */
    @Bean
    public WxMpService wxMpAndroidService() {
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(wxProperties.getAndroid().getAppId());
        wxMpDefaultConfig.setSecret(wxProperties.getAndroid().getAppSecret());
        WxMpServiceImpl wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpDefaultConfig);
        return wxMpService;
    }

    /**
     * 微信IOS配置
     *
     * @author hanyulin
     * @date 2022/1/8 14:41
     * @return me.chanjar.weixin.mp.api.WxMpService
     */
    @Bean
    public WxMpService wxMpIosService() {
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(wxProperties.getAndroid().getAppId());
        wxMpDefaultConfig.setSecret(wxProperties.getAndroid().getAppSecret());
        WxMpServiceImpl wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpDefaultConfig);
        return wxMpService;
    }


}
